﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Common;
using MyWeb.Business;
using MyWeb.Data;
namespace MyWeb.Admins
{
    public partial class tblImgSize : System.Web.UI.Page
    {
        static bool Insert = false;
        protected void Page_Load(object sender, EventArgs e)  
        {
            if (!IsPostBack){Session["folder"] = "tblImgSize"; BindGrid();
            }
        }
private void BindGrid()
{
    grdtblImgSize.DataSource = tblImgSizeService.tblImgSize_GetByAll() ;
    grdtblImgSize.DataBind();
}
protected void btnThem_Click(object sender, EventArgs e)
{
    pnShow.Visible = false;
    pnUpdate.Visible = true;
    ControlClass.ResetControlValues(this);
    Session["upload"] = null;
    Insert=true;
}
protected void btnXoa_Click(object sender, EventArgs e)
{
    try
    {
        DataGridItem item = default(DataGridItem);
        for (int i = 0; i < grdtblImgSize.Items.Count; i++)
        {
            item = grdtblImgSize.Items[i];
            if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item)
            {
                if (((CheckBox)item.FindControl("ChkSelect")).Checked)
                {
                    string strId = item.Cells[1].Text;
                    try
                    {
                        tblImgSizeService.tblImgSize_Delete(strId);
                    }
                    catch
                    {
                    }
                }
            }
        }
        grdtblImgSize.CurrentPageIndex = 0;BindGrid();
    }
    catch
    {
    }
}
        protected void grdtblImgSize_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            Data.tblImgSizeInfo strCA = new tblImgSizeInfo();
strCA._sid = e.CommandArgument.ToString();
if  (e.CommandName=="Edit")
{
    DataTable dt = tblImgSizeService.tblImgSize_GetById(strCA);
    txt_sid.Text=dt.Rows[0]["_sid"].ToString();
    txt_swidth.Text=dt.Rows[0]["_swidth"].ToString();
    txt_sheight.Text=dt.Rows[0]["_sheight"].ToString();
    txt_sprice.Text=dt.Rows[0]["_sprice"].ToString();
    pnUpdate.Visible = true;
    pnShow.Visible = false;
}
else
{
    tblImgSizeService.tblImgSize_Delete(strCA._sid); BindGrid();
}
        }
        protected void lblBack_Click(object sender, EventArgs e)
        {
            pnUpdate.Visible = false;pnShow.Visible = true;Insert=false;
        }
        protected void lblUpdate_Click(object sender, EventArgs e)
        {
            string image = Session["upload"] == null ? "" : Session["upload"].ToString();
            #region[TestInput]
if (txt_sid.Text.Trim().Equals(""))
{
    WebMsgBox.Show("_sid không thể trống !");
    txt_sid.Focus();
    return;
}
            if (txt_swidth.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("_swidth không thể trống !");
                txt_swidth.Focus();
                return;
            }
            if (txt_sheight.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("_sheight không thể trống !");
                txt_sheight.Focus();
                return;
            }
            if 
                (txt_sprice.Text.Trim().Equals(""))
            {
                WebMsgBox.Show("_sprice không thể trống !");
                txt_sprice.Focus();
                return;
            }
#endregion
Data.tblImgSizeInfo obj=new Data.tblImgSizeInfo();
            obj._sid = txt_sid.Text;
            obj._swidth = txt_swidth.Text;
            obj._sheight = txt_sheight.Text;
            obj._sprice = txt_sprice.Text;
            if (Insert == true)
            {
                tblImgSizeService.tblImgSize_Insert(obj);
            }
            else
            {
                tblImgSizeService.tblImgSize_Update(obj);
            }
            BindGrid();
            pnShow.Visible = true;
            pnUpdate.Visible = false;
            Insert = false;
}protected void grdtblImgSize_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
    grdtblImgSize.CurrentPageIndex = e.NewPageIndex;
    BindGrid();
} 
        protected void grdtblImgSize_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;
            if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator))
            {
                if (itemType == ListItemType.Header)
                {
                    object checkBox = e.Item.FindControl("chkSelectAll");
                    if ((checkBox != null))
                    {
                        ((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}else{
string tableRowId = grdtblImgSize.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex + ")");((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex + ")");
}
                }
            }
        }
}
}